﻿using System;
using System.Collections.Generic;
using Godot;

namespace kemocard.Scripts.Hero;

public static class HeroFactory
{
    private static readonly Dictionary<string, Type> HeroTypeDict = new()
    {
        { "Chalux", typeof(Chalux) },
        { "Carter", typeof(Carter) },
        { "Collin", typeof(Collin) },
        { "Ellis", typeof(Ellis) },
        { "Forge", typeof(Forge) },
        { "Merlin", typeof(Merlin) },
        { "Rains", typeof(Rains) },
        { "Seth", typeof(Seth) },
        { "Star", typeof(Star) },
        { "Santos", typeof(Santos) },
        { "Typhoon", typeof(Typhoon) },
        { "Zeller", typeof(Zeller) },
    };

    /// <summary>
    /// 注册英雄脚本，HeroScript，重复注册会覆盖
    /// </summary>
    /// <param name="heroId">Id</param>
    /// <param name="heroType">脚本类</param>
    public static void RegisterHero(string heroId, Type heroType)
    {
        if (heroType == typeof(HeroScript))
        {
            HeroTypeDict[heroId] = heroType;
        }
    }

    public static HeroScript CreateHero(string heroId)
    {
        if (HeroTypeDict.TryGetValue(heroId, out var heroType))
        {
            return (HeroScript)Activator.CreateInstance(heroType);
        }

        GD.PrintErr($"无法找到英雄脚本, ID:{heroId}");
        return null;
    }
}